﻿using System;
using System.Windows;
using System.Windows.Controls;
using GameEngine.View.Components;
using GameEngine.Model.Data;
using GameEditor.View.Components;
using GameEngine.Clients.Silverlight.View.Components;
using System.Collections.Generic;

namespace SilverlightClientEditor.View.Components
{
    public partial class ThingTypePropertiesEditorUC : UserControl, IThingTypeEditorMenuView<int>
    {
        //GameThingTypesListUC creator = new GameThingTypesListUC();
        //readonly ChildWindow childWnd;
        public event OnButtonClickHandler<IThingTypeEditorMenuViewConstants.ButtonTags> OnExternalActionButtonClick;

        public ThingTypePropertiesEditorUC()
        {
            InitializeComponent();
            OkButton.Tag = IThingTypeEditorMenuViewConstants.ButtonTags.OK;
            CancelButton.Tag = IThingTypeEditorMenuViewConstants.ButtonTags.CANCEL;
            //childWnd = new ChildWindow()
            //{
            //    Content = creator
            //};
            //creator.OnAddShapeClick += new Action<string, string, object>(delegate(string itemTypeName, string shapeType, object shapeProps)
            //{
            //    if(OnAddShapeClick!=null)
            //        OnAddShapeClick(itemTypeName, shapeType, shapeProps);
            //});
            //creator.OnRemoveShapeClick += new Action<string, string>(delegate(string itemTypeName, string shapeName)
            //{
            //    if(OnRemoveShapeClick!=null)
            //        OnRemoveShapeClick(itemTypeName, shapeName);
            //});
            //creator.OnCreateItemClick +=new Action<string>(delegate(string arg1){
            //    if (OnCreateItemClick != null)
            //        OnCreateItemClick(arg1);
            //    childWnd.Close();
            //});
            //itemTypeListBox.SelectionChanged += new SelectionChangedEventHandler(itemListBox_SelectionChanged);
            viewComboBox.DisplayMemberPath = "Name";
        }

        //void itemListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    if (e.AddedItems.Count > 0 && OnItemTypeClick != null)
        //        OnItemTypeClick(e.AddedItems[0] as string);
        //}

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;
            if (OnExternalActionButtonClick != null)
                OnExternalActionButtonClick((IThingTypeEditorMenuViewConstants.ButtonTags)button.Tag);
            //if (sender.Equals(addButton))
            //{
            //    if(OnAddItemClick!=null)
            //        OnAddItemClick(itemTypeListBox.SelectedItem as string);
            //}
            //else if (sender.Equals(createButton))
            //{
            //    if (OnNewItemClick != null)
            //        OnNewItemClick();
            //}
        }

        //public void ShowCreateWindow() {
        //    childWnd.Show();
        //}
        
        //#region ITileMapEditorMenuView Members

        //public event Action<string, string, object> OnAddShapeClick;
        //public event Action<string, string> OnRemoveShapeClick;
        //public event Action<string> OnCreateItemClick;
        //public event Action<string> OnAddItemClick;
        //public event Action OnNewItemClick;
        //public event Action<string> OnItemTypeClick;

        //public void AddShapeToList(string shape) {
        //    creator.AddShapeToList(shape);
        //}

        //public void RemoveShapeFromList(string shape) {
        //    creator.RemoveShapeFromList(shape);
        //}

        //public void RemoveAllShapesFromList() {
        //    //creator.RemoveAllShapes();
        //}

        //public void AddTypeToList(string type) {
        //    itemTypeListBox.Items.Add(type);
        //}

        //#endregion

        //public void SetItemEditorWorldView(WorldUC world)
        //{
        //    //creator.Initialize(world);
        //}

        //public event Action<string> OnCreateClick;

        //public event Action<string> OnEditClick;

        //public event Action<string> OnRemoveClick;

        //public event Action OnNewClick;

        //public void RemoveTypeFromList(string type)
        //{
        //    throw new NotImplementedException();
        //}

        public void AddView(IViewVOId<int> id) { viewComboBox.Items.Add(id); }
        public void RemoveView(IViewVOId<int> id) { viewComboBox.Items.Remove(id); }
        public List<IViewVOId<int>> GetViews()
        {
            List<IViewVOId<int>> result = new List<IViewVOId<int>>();
            foreach (var obj in viewComboBox.Items)
            {
                result.Add(obj as IViewVOId<int>);
            }
            return result;
        }
        public IViewVOId<int> SelectedView
        {
            get { return viewComboBox.SelectedItem as IViewVOId<int>; }
        }

        public void AddType(string id) { itemTypeComboBox.Items.Add(id); }
        public void RemoveType(string id) { itemTypeComboBox.Items.Remove(id); }
        public List<string> GetTypes()
        {
            List<string> result = new List<string>();
            foreach (var obj in itemTypeComboBox.Items)
            {
                result.Add(obj as string);
            }
            return result;
        }
        public string SelectedType
        {
            get { return itemTypeComboBox.SelectedItem as string; }
        }

        public string ThingTypeName {
            get { return ThingTypeNameTextBox.Text; }
            set { ThingTypeNameTextBox.Text = value; }
        }
    }
}